package nc.ui.med.pub.tools;

import java.awt.Container;

import nc.bs.logging.Logger;
import nc.ui.pub.ToftPanel;
import nc.vo.gsp.pub.lang.ResBase;
import nc.vo.pub.BusinessException;

public class GenMethod {

	public static BusinessException handleException(Container tfui, String msg, Throwable e) {
		
		Logger.error(msg, e);

		if (tfui != null) {
			BusinessException be = nc.vo.med.pub.GenMethod.getRealBusiException(e);
			if ((msg == null || msg.trim().length() <= 0) && be != null)
				msg = be.getMessage();
			if (msg == null)
				msg = ResBase.getStopAction();
			if (be == null)
				be = new BusinessException(e.getMessage(), e);
			showErro(tfui, be.getMessage());
			return be;
		}

		BusinessException be = nc.vo.med.pub.GenMethod.getRealBusiException(e);
		if (be != null)
			return be;
		else
			return new BusinessException(msg == null ? e.getMessage() : msg, e);
	}

	public static void showErro(Container parent, String msg) {

		if (parent != null && parent instanceof ToftPanel)
			((ToftPanel) parent).showErrorMessage(msg);
		else
			nc.ui.pub.beans.MessageDialog.showErrorDlg(parent, null, msg);
		return;
	}

}
